class CiotPairNetGuidInfo {
  final String id;
  final String pid;
  final int type;
  final List<CiotPairNetGuidStep> steps;
  final String? btText;
  final String networkNotice;

  const CiotPairNetGuidInfo({
    required this.id,
    required this.pid,
    required this.type,
    required this.steps,
    required this.btText,
    required this.networkNotice,
  });

  factory CiotPairNetGuidInfo.fromJson(Map<String, dynamic> json) {
    final confirmList = (json['confirmCopyList'] as List<dynamic>? ?? const [])
        .whereType<Map<String, dynamic>>()
        .toList();
    final netWorkNotice = (json['networkNotice'] as List<dynamic>? ?? const [])
        .whereType<Map<String, dynamic>>()
        .toList();

    return CiotPairNetGuidInfo(
      id: json['id']?.toString() ?? '',
      pid: json['pid']?.toString() ?? '',
      type: json['type'] is int
          ? json['type'] as int
          : int.tryParse(json['type']?.toString() ?? '') ?? 0,
      steps: (json['steps'] as List<dynamic>? ?? const [])
          .whereType<Map<String, dynamic>>()
          .map(CiotPairNetGuidStep.fromJson)
          .toList(),
      btText: confirmList.first['chinese'],
      networkNotice: netWorkNotice.first['chinese'],
    );
  }

  factory CiotPairNetGuidInfo.copyWith(CiotPairNetGuidInfo data) {
    return CiotPairNetGuidInfo(
      id: data.id,
      pid: data.pid,
      type: data.type,
      steps: data.steps.map(CiotPairNetGuidStep.copyWith).toList(),
      btText: data.btText,
      networkNotice: data.networkNotice,
    );
  }
}

class CiotPairNetGuidStep {
  final String code;
  final String? chinese;
  final String? english;
  final String? fileUrl;

  const CiotPairNetGuidStep({
    required this.code,
    this.chinese,
    this.english,
    this.fileUrl,
  });

  factory CiotPairNetGuidStep.fromJson(Map<String, dynamic> json) {
    final copyJson = (json['copy'] as List<dynamic>? ?? const [])
        .whereType<Map<String, dynamic>>()
        .toList();
    return CiotPairNetGuidStep(
      code: json['code']?.toString() ?? '',
      chinese: copyJson.first['chinese']?.toString(),
      english: copyJson.first['english']?.toString(),
      fileUrl: json['fileUrl']?.toString(),
    );
  }

  factory CiotPairNetGuidStep.copyWith(CiotPairNetGuidStep step) {
    return CiotPairNetGuidStep(
      code: step.code,
      chinese: step.chinese,
      english: step.english,
      fileUrl: step.fileUrl,
    );
  }
}
